using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace Common
{
    public class Validator
    {
        public bool checkDuplicate(String input, DataTable tb1, int c1)
            //String input: text can kiem tra
            // tb1: table dung de so sanh 
            // c1: index cot muon kiem tra 0,1,2...
        {
            if (input == "")
            {
                return true;
            }
            for (int i = 0; i < tb1.Rows.Count; i++)
            {
                if (input.ToUpper() == tb1.Rows[i][c1].ToString().ToUpper())
                {
                    return true;
                }
            }

            return false;
        }

        public bool checkNumber(String input)  
            // Kiem tra co phai la so hay khong
            // Kiem tra co de trong hay khong
        {
            if (input == "")
                return false;
            double outNum;
            bool isNum = double.TryParse(input, out outNum);
            if (isNum)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public bool checkEmail(String email)
        {
            if (email == " ")
                return true;

            int es = email.IndexOf("@");
            int dot = 0;
            if (es > 1)
            {
                dot = email.IndexOf(".", es);
            }
            
            if((es > 1) && (dot-es > 1))
                return true;
            else
                return false;
        }

        public string NullError(String input)
        {
            if (input == "")
                input = " ";
            return input;
        }

        public string returnNull(String input)
        {
            if (input == " ")
            {
                input = "";
            }
            return input;
        }
    }
    

}
